<template>
  <el-card shadow="never" class="mb10">
    <el-row>
      <el-form :inline="true" :model="queryData">
        <el-form-item label="姓名">
          <el-input placeholder="请输入姓名" v-model="queryData.keyWord" />
        </el-form-item>
        <el-form-item label="手机号码">
          <el-input placeholder="请输入手机号码" v-model="queryData.keyWord" />
        </el-form-item>
        <el-form-item label="状态">
          <el-select
            class="my-select"
            v-model="queryData.keyWord"
            placeholder="请选择状态"
          >
            <el-option label="兑换成功" value="1"> </el-option>
            <el-option label="未兑换" value="2"> </el-option>
            <el-option label="兑换失败" value="3"> </el-option>
            <el-option label="兑换中" value="4"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="申请时间">
          <el-date-picker
            v-model="queryData.date"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          />
        </el-form-item>
      </el-form>
      <div class="flex-right">
        <el-button type="primary" :icon="RefreshLeft">重置</el-button>
        <el-button
          type="primary"
          :icon="Search"
          class="ml20"
          @click="initData"
          v-enter="initData"
        >
          搜索
        </el-button>
      </div>
    </el-row>
  </el-card>
  <el-card shadow="never">
    <div class="mb10">
      <el-button type="primary" @click="dialogImportRef.openDialog()">
        兑换
      </el-button>
    </div>

    <el-table
      border
      stripe
      :data="tableData"
      
    >
      <el-table-column type="index" width="55" label="序号"></el-table-column>
      <el-table-column
        v-for="item in options"
        :key="item.type"
        :prop="item.props"
        :label="item.label"
        :width="item.width"
        :align="item.align"
        show-overflow-tooltip
        :fixed="item.fixed"
      >
        <template v-slot:default="scope" v-if="item.props === 'actions'">
          <el-button
            type="primary"
            text
            size="small"
            @click="onDialogStaff(scope)"
          >
            明细
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      class="mt-4"
      :total="total"
      :page-size="queryData.size"
      :page-sizes="[10, 20, 50, 100]"
      layout="total, sizes, prev, pager, next"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
  </el-card>

  <DialogComp ref="dialogCompRef"></DialogComp>
  <DialogImport ref="dialogImportRef"></DialogImport>
</template>

<script setup>
import { Search, RefreshLeft } from "@element-plus/icons-vue";
import { getUserList } from "@/api/index.js";
import { options } from "./options.js";
import { onMounted, ref } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import DialogComp from "./components/dialogComp.vue";
import DialogImport from "./components/dialogImport.vue";

const queryData = ref({
  keyWord: "",
  page: 1,
  size: 20,
});
const dialogCompRef = ref();
const dialogImportRef = ref();

const tableData = ref([]);
const total = ref(0);

const initData = () => {
  getUserList(queryData.value).then((res) => {
    total.value = res.data.data.total;
    tableData.value = res.data.data.userList;
  });
};

const handleCurrentChange = (val) => {
  queryData.value.pageNo = val;
  initData(queryData.value);
};
const handleSizeChange = (val) => {
  queryData.value.pageSize = val;
  initData(queryData.value);
};

const onDialogStaff = (row = null) => {
  dialogCompRef.value.openDialog(row);
};

onMounted(() => {
  initData();
});
</script>
